﻿<UserControl xmlns:reporting="clr-namespace:System.Windows.Printing.Reporting;assembly=Silverlight.Reporting"  x:Class="Silverlight.Reporting.TestClient.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">
        <StackPanel Orientation="Vertical">
            <Button x:Name="LoadData"
                    Content="Load Data"
                    Width="170"
                    Height="30"
                    Margin="10"
                    Click="LoadData_Click" />
            <Button x:Name="PrintReport"
                    Content="Print Report"
                    Width="170"
                    Height="30"
                    Margin="10"
                    IsEnabled="false"
                    Click="PrintReport_Click" />
            <Button x:Name="PrintReportForceVector"
                    Content="Print Report (Force Vector)"
                    Width="170"
                    Height="30"
                    Margin="10"
                    IsEnabled="false"
                    Click="PrintReportForceVector_Click" />
            <TextBlock x:Name="StatusText"
                       Text="Load Data and Print report"
                       Margin="10"
                       HorizontalAlignment="Center" />
        </StackPanel>


        <reporting:Report x:Name="Report"
                      Title="Employee Review List">
            
            <reporting:Report.Resources>
                <Style x:Key="HeaderText"
                       TargetType="TextBlock">
                    <Setter Property="FontWeight"
                            Value="Bold" />
                    <Setter Property="TextAlignment"
                            Value="Left" />
                    <Setter Property="HorizontalAlignment"
                            Value="Stretch" />
                </Style>
            </reporting:Report.Resources>
            
            
            <reporting:Report.PageHeaderTemplate>
                <DataTemplate>
                    <Grid Margin="1 1 1 20">
                        <Rectangle Stroke="Black" />

                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>

                            <TextBlock Text="{Binding Title}"
                                       Grid.Row="0"
                                       FontSize="16"
                                       FontWeight="Bold"
                                       Margin="5"
                                       HorizontalAlignment="Left"
                                       VerticalAlignment="Top" />

                            <TextBlock Text="{Binding CurrentPageNumber, StringFormat='Page {0}'}"
                                       Grid.Row="0"
                                       Margin="5"
                                       HorizontalAlignment="Right"
                                       VerticalAlignment="Top" />


                            <Grid Grid.Row="1" 
                                  HorizontalAlignment="Stretch"
                                  Margin="4 0 0 4">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="200" />
                                    <ColumnDefinition Width="200" />
                                    <ColumnDefinition Width="150" />
                                    <ColumnDefinition Width="150" />
                                </Grid.ColumnDefinitions>

                                <TextBlock Grid.Column="0"
                                           Style="{StaticResource HeaderText}"
                                           Text="Name and Address" />

                                <TextBlock Grid.Column="1"
                                           Style="{StaticResource HeaderText}"
                                           TextAlignment="Right"
                                           Text="Performance Rating" />

                                <TextBlock Grid.Column="2"
                                           Style="{StaticResource HeaderText}"
                                           TextAlignment="Right"
                                           Text="New Salary" />

                                <TextBlock Grid.Column="3"
                                           Style="{StaticResource HeaderText}"
                                           TextAlignment="Right"
                                           Text="Bonus" />


                            </Grid>
                        </Grid>
                    </Grid>
                </DataTemplate>
            </reporting:Report.PageHeaderTemplate>

            <reporting:Report.ItemTemplate>
                <DataTemplate>
                    <Grid HorizontalAlignment="Stretch"
                          Margin="5 0 0 20">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="200" />
                            <ColumnDefinition Width="200" />
                            <ColumnDefinition Width="150" />
                            <ColumnDefinition Width="150" />
                        </Grid.ColumnDefinitions>

                        <StackPanel Grid.Column="0"
                                    Orientation="Horizontal">
                            <TextBlock Text="{Binding LastName}"
                                       FontWeight="Bold" />
                            <TextBlock Text=", "
                                       FontWeight="Bold" />
                            <TextBlock Text="{Binding FirstName}"
                                       FontWeight="Bold" />
                        </StackPanel>

                        <TextBlock Grid.Column="1"
                                   Text="{Binding PerformanceRating}"
                                   TextAlignment="Left" />

                        <TextBlock Grid.Column="2"
                                   Text="{Binding Salary, StringFormat='{}{0:C}'}"
                                   TextAlignment="Right" />

                        <TextBlock Grid.Column="3"
                                   Text="{Binding Bonus, StringFormat='{}{0:C}'}"
                                   TextAlignment="Right" />

                        <StackPanel Grid.Row="1"
                                    Orientation="Horizontal"
                                    Grid.ColumnSpan="4">
                            <TextBlock Text="{Binding Street}" />
                            <TextBlock Text=" " />
                            <TextBlock Text="{Binding City}" />
                            <TextBlock Text=", " />
                            <TextBlock Text="{Binding State}" />
                            <TextBlock Text=" " />
                            <TextBlock Text="{Binding Zip}" />
                        </StackPanel>
                        
                        <!-- This tests binding of runs. Currently does not work. -->
                        <!--<TextBlock Grid.Row="2"
                                   Grid.ColumnSpan="4"
                                   TextWrapping="Wrap">
                            <Run Text="{Binding ReviewComments}" />
                        </TextBlock>-->
                        <TextBlock Grid.Row="2"
                                   Grid.ColumnSpan="4"
                                   TextWrapping="Wrap"
                                   Text="{Binding ReviewComments}" />
                    </Grid>
                </DataTemplate>
            </reporting:Report.ItemTemplate>

            <reporting:Report.PageFooterTemplate>
                <DataTemplate>
                    <Grid Margin="1 20 1 1">
                        <Rectangle Stroke="Black" />
                        <StackPanel Orientation="Horizontal"
                                    HorizontalAlignment="Right"
                                    VerticalAlignment="Center"
                                    Margin="5">
                            <TextBlock Text="{Binding CurrentPageNumber, StringFormat='Page {0}'}" />
                            <TextBlock Text="{Binding TotalPageCount, StringFormat=' of {0}'}" />

                        </StackPanel>
                    </Grid>
                </DataTemplate>
            </reporting:Report.PageFooterTemplate>

            <reporting:Report.ReportFooterTemplate>
                <DataTemplate>
                    <Grid Margin="1 20 1 1">
                        <Rectangle Stroke="Black" />

                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="200" />
                                <ColumnDefinition Width="200" />
                                <ColumnDefinition Width="150" />
                                <ColumnDefinition Width="150" />
                            </Grid.ColumnDefinitions>

                            <TextBlock Grid.Column="1"
                                       Text="{Binding EmployeeCount, StringFormat='{}{0} employees'}"
                                       TextAlignment="Left" />

                            <TextBlock Grid.Column="2"
                                       Text="{Binding TotalSalary, StringFormat='{}{0:C}'}"
                                       TextAlignment="Right" />

                            <TextBlock Grid.Column="3"
                                       Text="{Binding TotalBonus, StringFormat='{}{0:C}'}"
                                       TextAlignment="Right" />
                        </Grid>
                    </Grid>
                </DataTemplate>
            </reporting:Report.ReportFooterTemplate>


        </reporting:Report>


    </Grid>
</UserControl>
